package com.project.gcsj5.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.*;
import org.hibernate.annotations.CreationTimestamp;

import java.time.Instant;

/**
 * 书籍实体类
 * 对应数据库中的book表
 */
@TableName("book")
public class Book {
    @TableId(type = IdType.AUTO)  // 主键自增
    int id;                       // 书籍ID

    private String name;          // 书籍名称

    private String auther;        // 作者

    private String content;       // 书籍内容简介

    private float stars;          // 评分（星级）

    @Temporal(TemporalType.TIMESTAMP)  // 时间类型
    @CreationTimestamp                 // 自动创建时间戳
    private Instant time;         // 创建时间

    private String img_url;       // 书籍封面图片URL

    private String category;      // 书籍分类

    private int view_sum;        // 浏览次数

    /**
     * 无参构造函数
     */
    public Book() {
    }

    /**
     * 全参构造函数
     * @param id 书籍ID
     * @param name 书籍名称
     * @param auther 作者
     * @param content 内容简介
     * @param stars 评分
     * @param time 创建时间
     * @param img_url 封面图片URL
     * @param category 分类
     * @param view_sum 浏览次数
     */
    public Book(int id, String name, String auther, String content, float stars, Instant time, String img_url, String category, int view_sum) {
        this.id = id;
        this.name = name;
        this.auther = auther;
        this.content = content;
        this.stars = stars;
        this.time = time;
        this.img_url = img_url;
        this.category = category;
        this.view_sum = view_sum;
    }

    // 以下是各属性的getter和setter方法

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuther() {
        return auther;
    }

    public void setAuther(String auther) {
        this.auther = auther;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public float getStars() {
        return stars;
    }

    public void setStars(float stars) {
        this.stars = stars;
    }

    public Instant getTime() {
        return time;
    }

    public void setTime(Instant time) {
        this.time = time;
    }

    public String getImg_url() {
        return img_url;
    }

    public void setImg_url(String img_url) {
        this.img_url = img_url;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getView_sum() {
        return view_sum;
    }

    public void setView_sum(int view_sum) {
        this.view_sum = view_sum;
    }

    /**
     * toString方法
     * @return 返回书籍ID的字符串表示
     */
    @Override
    public String toString() {
        return "Comment{id=" + id + "'}";
    }
}